package com.carkeeper.storebill.controller;

import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.storebill.pojo.StoreBill;
import com.carkeeper.storebill.pojo.StoreBillShow;
import com.carkeeper.storebill.service.StoreBillService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api( tags = "StoreBill(账单模块) 测试功能接口")
@RestController
@RequestMapping("/storebill")
@CrossOrigin
public class StoreBillController {

    @Autowired
    StoreBillService storeBillService;

    @GetMapping("/findByCondition")
    public Result<StoreBill> findByCondition(@RequestParam Map map){

        PageInfo info = storeBillService.findByCondition(map);

        return new Result<>(true, StatusCode.OK, "查询成功",info);
    }


    /**
     * 根据code查询账单信息
     * @param code 账单编码
     * @return 账单,车主，商家组合实体（Map）
     */
    @GetMapping("/findByCode")
    public Result<Map> findByCode(@RequestParam() String code){

        Map<String, Object> result = storeBillService.findByCode(code);

        return new Result<>(true, StatusCode.OK, "查询成功",result);
    }

    /**
     * 查询所有的支付状态
     * @return 支付状态的集合
     */
    @GetMapping("/findPayStatusList")
    public Result<List> findPayStatusList(){

        List<String> payStatusList = storeBillService.findPayStatusList();

        return new Result<>(true, StatusCode.OK, "查询成功",payStatusList);
    }

    /**
     * 以商家聚合查询所有商家账单概要
     * @return
     * 用于服务商账单支付页面数据初始化
     */
    @GetMapping("/findShowStoreBill")
    public Result<List> findShowStoreBill(@RequestParam Map<String,String> searchMap){

        PageInfo<StoreBillShow> info = storeBillService.findShowStoreBill(searchMap);

        return new Result<>(true, StatusCode.OK, "查询成功",info);
    }

    /**
     * 根据商家id查询所有未支付的账单
     * @param storeId
     * @return 账单集合
     */
    @GetMapping("/findNotPayStoreBillByStoreId/{storeId}")
    public Result<Map> findNotPayStoreBillByStoreId(@PathVariable("storeId") Integer storeId,@RequestParam Map<String,String> searchMap){

        Map<String,Object> resultMap = new HashMap<String,Object>();
        List<StoreBill> storeBills = storeBillService.findNotPayStoreBillByStoreId(storeId,searchMap);

        //调用feign根据id查询商家
        resultMap.put("storeBills",storeBills);

        return new Result<>(true, StatusCode.OK, "查询成功",resultMap);
    }

}
